#include "cont.h"


void Cont::addFigure(Shape * newFigure)
{
    shapes.push_back(newFigure);
}
void Cont::deleteFigure(int i)
{
    delete shapes.at(i-1);
    shapes.erase(shapes.begin() + i - 1);
}
void Cont::moveToNewXY(int newX, int newY, int i)
{
    shapes.at(i)->offsetToNewXY(newX, newY);
}

void Cont::saveFile()
{
    ofstream file("output.txt");
    for (int i = 0; i < shapes.size(); i++)
    {
        vector<int> tmp = shapes.at(i)->getProperties();
        file << shapes.at(i)->Type()[0]<<endl;
        for (int j = 0; j < tmp.size(); j++)
        {

            file << tmp.at(j) << endl;
        }
    }

    file.close();
}
void Cont::loadFile()
{
    ifstream file("output.txt");
    if (file.is_open())
    {
        while (true) {
            if (file.eof()) { break; }
            else{

            char tmp;
            file >> tmp;
            if (!file.good())
                break;
            Shape *figure;
            switch (tmp)
            {
            case 'R':{
                int x, y, weight, height;
                file >> x >> y >> weight >> height;
                figure = new Rectangle(x, y, weight, height);
                break; }
            case 'C':{
                int x, y, radius;
                file >> x >> y >>radius ;
                figure = new Circle(x, y,radius );
                break; }
            case 'S':{
                int x, y, weight;
                file >> x >> y >> weight;
                figure = new Square(x, y, weight);
                break; }
            }

            shapes.push_back(figure);}
        }
    }
    file.close();
}
void Cont::printTypeShapes()
{
    for (int i = 0; i < shapes.size(); i++)
        cout<<shapes.at(i)->Type()<<endl;
}

